package main

import (
	"context"
	"fmt"
	pb "goproject/grpc/Demo/server/proto"
	"net"

	"google.golang.org/grpc"
)

type server struct {
	pb.UnimplementedHelloStudentServer
}

func (s *server) HelloStudent(ctx context.Context, req *pb.StudentRequest) (*pb.StudentResponse, error) {
	return &pb.StudentResponse{ResponseMsg: "hello student:" + req.Name}, nil
}

func main() {
	// 开启端口
	listen, _ := net.Listen("tcp", "127.0.0.1:8080")
	grpcServer := grpc.NewServer()
	pb.RegisterHelloStudentServer(grpcServer, &server{})
	err := grpcServer.Serve(listen)
	if err != nil {
		fmt.Println("启动失败", err)
	}

}

/*
func RegisterHelloStudentServer(s grpc.ServiceRegistrar, srv HelloStudentServer) {
	// If the following call pancis, it indicates UnimplementedHelloStudentServer was
	// embedded by pointer and is nil.  This will cause panics if an
	// unimplemented method is ever invoked, so we test this at initialization
	// time to prevent it from happening at runtime later due to I/O.
	if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
		t.testEmbeddedByValue()
	}
	s.RegisterService(&HelloStudent_ServiceDesc, srv)

*/
